package com.rtx.edi.platform.jobextend.controller;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rtx.api.enums.FieldValidateType;
import com.rtx.api.utils.FieldValidateUtils;
import com.rtx.edi.model.response.EdiResponse;
import com.rtx.edi.platform.jobextend.bean.dto.PlJobDetailDTO;
import com.rtx.edi.platform.jobextend.bean.po.PlJobDetail;
import com.rtx.edi.platform.jobextend.service.PlJobDetailService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = {"调度任务明细"})
@RequestMapping("/v1/edi/plJobdetail")
@RestController
public class PlJobDeatilController {
	
	@Autowired
	PlJobDetailService plJobDetailService;
	
	@ApiOperation(value = "查询调度任务明细_分页", notes = "查询调度任务_分页")
	@PostMapping("selectJobDetailPage")
	public EdiResponse selectPlJobdetailList(@RequestBody(required = false) PlJobDetailDTO dto){
		PlJobDetail po = new PlJobDetail();
		BeanUtils.copyProperties(dto, po);
		
		Page<PlJobDetail> pageParam = new Page<>(dto.getPageNum(), dto.getPageSize());
		plJobDetailService.selectPage(pageParam, po);
		return EdiResponse.success().data("page",pageParam);
	}
	
	@ApiOperation(value = "新增调度任务明细", notes = "新增调度任务明细")
	@PostMapping("addJobDetail")
	public EdiResponse addjobDetail(@RequestBody(required = false) PlJobDetailDTO dto){
		FieldValidateUtils.fieldNotNull(dto, FieldValidateType.INSERT);
		
		PlJobDetail po = new PlJobDetail();
		BeanUtils.copyProperties(dto, po);
		
		plJobDetailService.save(po);
		return EdiResponse.success();
	}
	
	@ApiOperation(value = "修改调度任务明细", notes = "修改调度任务明细")
	@PostMapping("updJobDetail")
	public EdiResponse updjobDetail(@RequestBody(required = false) PlJobDetailDTO dto){
		FieldValidateUtils.fieldNotNull(dto, FieldValidateType.INSERT);
		
		PlJobDetail po = new PlJobDetail();
		BeanUtils.copyProperties(dto, po);
		
		plJobDetailService.updateById(po);
		return EdiResponse.success();
	}
	
	@ApiOperation(value = "删除调度任务明细_批量", notes = "删除调度任务明细_批量")
	@PostMapping("delJobDetailbatch")
	public EdiResponse deljobDetail(@RequestBody(required = false) List<PlJobDetailDTO> list){
		List<Long> ids = list.stream().map(dto->dto.getId()).collect(Collectors.toList());
		plJobDetailService.removeBatchByIds(ids);
		return EdiResponse.success();
	}
	
	@ApiOperation(value = "删除调度任务明细_通过id", notes = "删除调度任务明细_通过id")
	@PostMapping("delJobDetailById")
	public EdiResponse deljobDetail(@RequestBody(required = false) PlJobDetailDTO dto){
		plJobDetailService.removeById(dto.getId());
		return EdiResponse.success();
	}
}
